package com.mayikt.manage;

import com.mayikt.entity.UserEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

/**
 * @ClassName LoginManage
 * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com
 * @Version V1.0
 **/
@Component
@Slf4j
public class LoginManage {
    @Async
    public Future<String> asynLogin(UserEntity userEntity) {
        loginLog(userEntity);
        sendSms(userEntity);
        sendEmail(userEntity);
        return new AsyncResult<String>("异步发送短信成功");
    }

    private UserEntity dbLogin(UserEntity userEntity) {
        log.info(">>>1.正在查询数据库登陆<<<");
        try {
            Thread.sleep(2000);
        } catch (Exception e) {

        }
        return new UserEntity();
    }

    private void loginLog(UserEntity userEntity) {
        log.info(">>>2.异步开始写登陆的日志<<<");
        try {
            Thread.sleep(2000);
        } catch (Exception e) {

        }
//        int i = 1 / 0;
    }

    private void sendSms(UserEntity userEntity) {
        log.info(">>>3.异步开始发送短信<<<");
        try {
            Thread.sleep(2000);
        } catch (Exception e) {

        }
    }

    private void sendEmail(UserEntity userEntity) {
        log.info(">>>4.异步开始发送邮件<<<");
        try {
            Thread.sleep(2000);
        } catch (Exception e) {

        }
    }
}
